﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Tag : MonoBehaviour
{
    public enum Style
    {
        STYEL_DEFUALT,

    }
    public Style m_Style;
    public GameObject m_BindObj;
    public Image m_Icon;
    public Text m_DistanceL;
    public Text m_NameL;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (!m_BindObj)
        {
            if (gameObject.activeSelf)
                gameObject.SetActive(false);
            return;
        }

        if (!gameObject.activeSelf)
            gameObject.SetActive(true);

        RectTransform rectTransform = GetComponent<RectTransform>();
        var calcPosition = UtilsUnity.GetPositionInScreen(Camera.main.WorldToScreenPoint(m_BindObj.transform.position), rectTransform.sizeDelta, UtilsUnity.Align.ALIGN_LEFT_TOP);

        float scale = 1;
        var cavas = UtilsUnity.GetCanvas();
        if (cavas && cavas.scaleFactor > 0)
            scale = 1f / cavas.scaleFactor;
        calcPosition *= scale;
        rectTransform.anchoredPosition = calcPosition;

        var currentShip = Player.Instance.GetCurrentShip();
        if (m_DistanceL && currentShip)
        {
            m_DistanceL.text = "距离："+(currentShip.transform.position - m_BindObj.transform.position).magnitude.ToString("f2") + "km";
        }

    }
}
